#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //测试按钮
    test_button = new QPushButton(this);
    test_button->move(100, 100);
    test_button->setText("测试按钮");
    //改变测试按钮状态的按钮
    change_button = new QPushButton(this);
    change_button->move(100, 150);
    change_button->setText("改变状态按钮");

    connect(test_button, &QPushButton::clicked, this, &Widget::PressButton);
    connect(change_button, &QPushButton::clicked, this, &Widget::ChangeEnableStatus);
}

Widget::~Widget()
{
    delete ui;
}

//按下按钮触发的操作
void Widget::PressButton()
{
    qDebug() << "测试按钮被按下";
}

void Widget::ChangeEnableStatus()
{
    //获取控件可用状态
    bool flag = test_button->isEnabled();
    //改变控件可用状态
    if(flag)
        test_button->setEnabled(false);
    else
        test_button->setEnabled(true);
}

